#include <vector>
using std::vector;

//旋转数组查最小值
//对右范围作判断

class Solution_1 {
public:
    int findMin(vector<int>& nums) {
        int size = nums.size();
        int left = 0;
        int right = size - 1;
        while (left < right) {
            int mid = left + (right - left) / 2;
            if (nums[mid] < nums[right])
                right = mid;
            else 
                left = mid + 1; 
        }
        return nums[left];
    }
};

//若存在重复元素进行单独的位移

class Solution_2 {
public:
    int findMin(vector<int>& nums) {
        int left = 0;
        int right = nums.size() - 1;
        while (left < right) {
            int mid = left + (right - left) / 2;
            if (nums[mid] < nums[right])
                right = mid;
            else if(nums[mid] == nums[right])
                right = right - 1;
            else if(nums[mid] == nums[left])
                left = left + 1;
            else
                left = mid + 1;
        }
        return nums[left];
    }
};